package com.zhuoshi.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.zhuoshi.entity.Client;
import com.zhuoshi.service.ClientService;
/*
 * Author:海生
 */
@Controller
@RequestMapping(value="client")
public class ClientListContorller {
	
	@Autowired
	private ClientService clientService;
	
	//查询所有客户基本信息
	@RequestMapping("clientList.action")
	public ModelAndView selectClientAllLu(HttpServletRequest request,HttpServletResponse response) throws Exception{
		List <Client> clientList = clientService.selectClientAllLu();
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("clientList",clientList);
		modelAndView.setViewName("/Admin/KeHuJiChuXinXiGuanLi.jsp");
		return modelAndView;		
	}
	
	//跳转到添加页面
	@RequestMapping("clientTianjia.action")
	public ModelAndView ClientLuTianjia(HttpServletRequest request, HttpServletResponse response,Client client) throws Exception{		
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("/Admin/AddKeHuJiChuXinXiGuanLi.jsp");
		return modelAndView;
	}
	
	//添加客户信息
	@RequestMapping("clientAdd.action")
	public String addClientLu(HttpServletRequest request, HttpServletResponse response,Client client) throws Exception{
		int a = clientService.addClientLu(client);		
		if(a>0){
			return "redirect:clientList.action";
			
		}else{
			return "redirect:clientTianjia.action";			
		}		
	}
	
	//删除客户信息
	@RequestMapping("clientDelete.action")
	public String  deleteByClientIdLu(HttpServletRequest request, HttpServletResponse response,int id) throws Exception{
		System.out.println("id:"+id);
		int a = clientService.deleteClient(id);
		if(a>0){
			return "redirect:clientList.action";			
		}else{
			return "/error.jsp";	
		}
	}
	
	//修改客户信息显示页面
	@RequestMapping("selectClient.action")
	public ModelAndView selectClientByIdLu(HttpServletRequest request, HttpServletResponse response,int id) throws Exception{
		Client client = clientService.selectClient(id);
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("client", client);
		modelAndView.setViewName("/Admin/UpdateKeHuXinXi.jsp");
		return modelAndView;
	}
	
	//修改客户信息
	@RequestMapping("updateClient.action")
	public String updateClientLu(HttpServletRequest request, HttpServletResponse response,Client client) throws Exception{
		int a = clientService.updateClient(client);
		if(a>0){
			return "redirect:clientList.action";
		}else{
			return "/error.jsp";
		}
	}

	//模糊查询客户信息
	@RequestMapping("mohuSelectClient.action")
	public ModelAndView mohuSelectClientLu(Client client) throws Exception{
		List<Client> clientList = clientService.mohuSelectClient(client);
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("clientList", clientList);
		modelAndView.setViewName("/Admin/KeHuJiChuXinXiGuanLi.jsp");
		return modelAndView;
	}
	
}
